﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;//添加System.Configuration.dll的引用
using System.Collections.Specialized;


using log4net;
using log4net.Config;
using System.Reflection;



namespace AutoRule
{
    class CConfig
    {
        private static CConfig _instance;
        private CConfig()
        {
        
        }
        public static CConfig GetInstance()
        {
            if (_instance == null)
            {
                _instance = new CConfig();
            }
            return _instance;
        }

        public void Init()
        {
            string sExePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            int index = sExePath.LastIndexOf("\\");
            sExePath = sExePath.Substring(0, index + 1);
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ExeConfigurationFileMap map = new ExeConfigurationFileMap();
            map.ExeConfigFilename = (sExePath + "App.config");
            config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);

            _OpcSvrIp = config.AppSettings.Settings["OpcSvrIp"].Value;
            ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            log.Debug("!!!!!!!!!!!!!!!!!!!!opc svr ip:" + _OpcSvrIp);
            _OpcSvrPort = config.AppSettings.Settings["OpcSvrPort"].Value;
            _dbip = config.AppSettings.Settings["ServerIP"].Value; //ConfigurationManager.AppSettings.Get("ServerIP");
            _dbname = config.AppSettings.Settings["DataBase"].Value; //ConfigurationManager.AppSettings.Get("DataBase");
            _dbuser = config.AppSettings.Settings["user"].Value; //ConfigurationManager.AppSettings.Get("user");
            _dbpwd = config.AppSettings.Settings["password"].Value; //ConfigurationManager.AppSettings.Get("password");
            _localserverport = config.AppSettings.Settings["localserverport"].Value; //ConfigurationManager.AppSettings.Get("password");
            _summerstart = int.Parse(config.AppSettings.Settings["summerstart"].Value);
            _summerend = int.Parse(config.AppSettings.Settings["summerend"].Value);
            _winnterstart = int.Parse(config.AppSettings.Settings["winnterstart"].Value);
            _winnterend = int.Parse(config.AppSettings.Settings["winnterend"].Value);
        
        }

        public String _OpcSvrIp = "";
        public String _OpcSvrPort = "";
        public String _dbip = "";
        public String _dbname = "";
        public String _dbuser = "";
        public String _dbpwd = "";
        public String _localserverport = "";
        public int _summerstart;
        public int _summerend;
        public int _winnterstart;
        public int _winnterend;
    }


    

}
